//
//  ZSValidateString.m
//  WeSchoolStudent
//
//  Created by safiri on 15/9/28.
//  Copyright © 2015年 safiri. All rights reserved.
//

#import "ZSValidateString.h"

@implementation ZSValidateString

//邮箱
//+ (BOOL) validateEmail:(NSString *)email
//{
//    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
//    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
//    return [emailTest evaluateWithObject:email];
//}


//手机号码验证
+ (BOOL) validateMobile:(NSString *)mobile {
    
    NSString *phoneRegex = @"^1[3-9]\\d{9}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
    
    //return mobile.trimSpace.length == 11;
}


//车牌号验证
//+ (BOOL) validateCarNo:(NSString *)carNo {
//    NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$";
//    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
//    NSLog(@"carTest is %@",carTest);
//    return [carTest evaluateWithObject:carNo];
//}


//车型
//+ (BOOL) validateCarType:(NSString *)CarType {
//    NSString *CarTypeRegex = @"^[\u4E00-\u9FFF]+$";
//    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CarTypeRegex];
//    return [carTest evaluateWithObject:CarType];
//}


//用户名
//+ (BOOL) validateUserName:(NSString *)name {
//    //3~20位字母、数字组成
//    NSString *userNameRegex = @"^[A-Za-z0-9]{3,20}+$";
//    NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
//
//    return [userNamePredicate evaluateWithObject:name];
//}
//用户名
//+ (BOOL) validateUsername:(NSString *)userName{
//    //2~20位字母、数字、下划线组成
//    NSString *userNameRegex = @"/^([a-zA-Z0-9]|[_]){2,20}/$";
//    NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
//    return [userNamePredicate evaluateWithObject:userName];
//}
//昵称
+ (BOOL) validateNickname:(NSString *)nickname {
    //非特殊符号2-12位
    NSString *nicknameRegex = @"^[\u4e00-\u9fa5A-Za-z0-9_]{0,12}$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",nicknameRegex];
    return [passWordPredicate evaluateWithObject:nickname];
}


//密码
+ (BOOL) validatePassword:(NSString *)passWord {
//    return passWord.length>=6;
    //密码应为6-20位非空格字符
    NSString *passWordRegex = @"^[@A-Za-z0-9]{6,20}$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:passWord];
}
//密码（注册）
+ (BOOL) validatePasswordForRegister:(NSString *)passWord {
    //请设置6-14位数字加字母的密码
    NSString *passWordRegex = @"^[@A-Za-z0-9]{6,14}$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    BOOL tag = [passWordPredicate evaluateWithObject:passWord];
    return tag;
//    if (!tag) {
//        return tag;
//    }
//    NSString *passWordRegex2 = @"[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]|\n|\r|\t";
//    NSPredicate *passWordPredicate2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex2];
//    BOOL tag2 = [passWordPredicate2 evaluateWithObject:passWord];
//    return tag2;
}

//身份证号
//+ (BOOL) validateIdentityCard: (NSString *)identityCard {
//    NSString *regex = @"^(\\d{6})(\\d{4})(\\d{2})(\\d{2})(\\d{3})([0-9]|X)$";
//    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
//    return [identityCardPredicate evaluateWithObject:identityCard];
//}
//纯数字字符串
+ (BOOL) validateNumberString:(NSString *)numberString {
    NSString *numberRegex = @"[0-9]+";
    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",numberRegex];
    return [resultPredicate evaluateWithObject:numberString];
}

//#pragma mark - 正则相关
//- (BOOL)ht_isValidateByRegex:(NSString *)regex{
//    NSPredicate *pre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
//    return [pre evaluateWithObject:self];
//}
//
//手机号分服务商
//- (BOOL)ht_isMobileNumberClassification {
//    /**
//     * 手机号码
//     * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188,1705
//     * 联通：130,131,132,152,155,156,185,186,1709
//     * 电信：133,1349,153,180,189,1700
//     */
//    //    NSString * MOBILE = @"^1((3//d|5[0-35-9]|8[025-9])//d|70[059])\\d{7}$";//总况
//
//    /**
//     10         * 中国移动：China Mobile
//     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188，1705
//     12         */
//    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d|705)\\d{7}$";
//    /**
//     15         * 中国联通：China Unicom
//     16         * 130,131,132,152,155,156,185,186,1709
//     17         */
//    NSString * CU = @"^1((3[0-2]|5[256]|8[56])\\d|709)\\d{7}$";
//    /**
//     20         * 中国电信：China Telecom
//     21         * 133,1349,153,180,189,1700
//     22         */
//    NSString * CT = @"^1((33|53|8[09])\\d|349|700)\\d{7}$";
//
//
//    /**
//     25         * 大陆地区固话及小灵通
//     26         * 区号：010,020,021,022,023,024,025,027,028,029
//     27         * 号码：七位或八位
//     28         */
//    NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
//
//
//    //    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
//
//    if (([self ht_isValidateByRegex:CM])
//        || ([self ht_isValidateByRegex:CU])
//        || ([self ht_isValidateByRegex:CT])
//        || ([self ht_isValidateByRegex:PHS]))
//    {
//        return YES;
//    }
//    else
//    {
//        return NO;
//    }
//}
//
////手机号有效性
//- (BOOL)ht_isMobileNumber{
//    NSString *mobileRegex = @"^(0|86|17951)?(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$";
//    BOOL ret1 = [self ht_isValidateByRegex:mobileRegex];
//    return ret1;
//}
//
////邮箱
//- (BOOL)ht_isEmail{
//    NSString *emailRegex = @"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
//    return [self ht_isValidateByRegex:emailRegex];
//}
//
////身份证号
//- (BOOL)ht_simpleIDCard{
//    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
//    return [self ht_isValidateByRegex:regex2];
//}
//
////车牌
//- (BOOL)ht_isCarNumber{
//    //车牌号:湘K-DE829 香港车牌号码:粤Z-J499港
//    NSString *carRegex = @"^[\u4e00-\u9fff]{1}[a-zA-Z]{1}[-][a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fff]$";//其中\u4e00-\u9fa5表示unicode编码中汉字已编码部分，\u9fa5-\u9fff是保留部分，将来可能会添加
//    return [self ht_isValidateByRegex:carRegex];
//}
////Mac地址
//- (BOOL)ht_isMacAddress{
//    NSString * macAddRegex = @"([A-Fa-f\\d]{2}:){5}[A-Fa-f\\d]{2}";
//    return  [self ht_isValidateByRegex:macAddRegex];
//}
////网址
//- (BOOL)ht_isValidUrl
//{
//    NSString *regex = @"^((http)|(https))+:[^\\s]+\\.[^\\s]*$";
//    return [self ht_isValidateByRegex:regex];
//}
////中文
//- (BOOL)ht_isValidChinese;
//{
//    NSString *chineseRegex = @"^[\u4e00-\u9fa5]+$";
//    return [self ht_isValidateByRegex:chineseRegex];
//}
////邮编
//- (BOOL)ht_isPostalcode {
//    NSString *postalRegex = @"^[0-8]\\d{5}(?!\\d)$";
//    return [self ht_isValidateByRegex:postalRegex];
//}
////工商税号
//- (BOOL)ht_isTaxNo
//{
//    NSString *taxNoRegex = @"[0-9]\\d{13}([0-9]|X)$";
//    return [self ht_isValidateByRegex:taxNoRegex];
//}
@end
/*
    常用正则表达式：http://tool.oschina.net/regex/#
    匹配中文字符：[\u4e00-\u9fa5]
    匹配双字节字符(包括汉字在内) ：[^\x00-\xff]
    匹配空白行 ：\n\s*\r
    匹配Email地址 ：[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?
    匹配网址URL ： [a-zA-z]+://[^\s]*
    匹配腾讯QQ号 : [1-9][0-9]{4,}
    匹配中国邮政编码 : [1-9]\d{5}(?!\d)
    匹配18位身份证号 : ^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$
    匹配(年-月-日)格式日期 : ([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))
    匹配正整数 : ^[1-9]\d*$
    匹配负整数 : ^-[1-9]\d*$
    匹配整数 : ^-?[1-9]\d*$
 */
